import { useState } from "react";
import { connect } from "react-redux";

function ComponentA({b_say, toB}) {
    const [a_say, set_a_say] = useState('')

    return <div>
        <p>我是组件A</p>
        <div>组件B对我说：{b_say}</div>
        我对组件B说：<input type="text" onChange={(e)=> {set_a_say(e.target.value)}} />
        <button onClick={()=> {toB(a_say)}}>确定</button>
    </div>
}

const mapStateToProps = state => ({b_say: state.info.b_say})
const mapDispatchToProps = dispatch => ({toB: (mes)=> dispatch({type: 'SET', payload: {a_say: mes}})})

export default connect(mapStateToProps, mapDispatchToProps)(ComponentA)